package com.ytjj.qmyx.data.amqp.consumer;

import com.rabbitmq.client.Channel;
import com.ytjj.common.constants.QueueConstants;
import com.ytjj.common.dto.mqdto.OrderRecordDto;
import com.ytjj.qmyx.data.service.OrderRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 *
 *  *
 **/
@Slf4j
@Component
public class OrderRecordListener {

    @Resource
    private OrderRecordService orderRecordService;

    @Transactional(rollbackFor = Exception.class)
    @RabbitListener(queuesToDeclare = @Queue(value = QueueConstants.ORDER_RECORD_QUEUE, durable = "true"))
    public void orderRecord(OrderRecordDto recordDto, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) {
        log.debug("收到一条消息orderRecord消息：" + recordDto+"");
        orderRecordService.addRecord(recordDto);
    }

//    @Transactional(rollbackFor = Exception.class)
//    @RabbitListener(queuesToDeclare = @Queue(value = QueueConstants.ORDER_RECORD_QUEUE_HISTORY, durable = "true"))
//    public void addRecordByHistory(OrderRecordDto recordDto, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) {
//        log.debug("收到一条消息addRecordByHistoryd消息：" + recordDto+"");
//        orderRecordService.addRecordByHistory(recordDto);
//    }
}
